package com.muqi.app.qlearn.mine;

import java.util.HashMap;

import org.json.JSONException;
import org.json.JSONObject;

import com.muqi.app.network.http.MyAsyncHttp;
import com.muqi.app.network.http.MyAsyncHttp.AsyncCallBackListener;
import com.muqi.app.network.http.ParamsUtils;
import com.muqi.app.network.http.MyAsyncHttp.RESULTCODE;
import com.muqi.app.project.contants.NetWorkApi;
import com.muqi.app.qlearn.student.BaseFragmentActivity;
import com.muqi.app.qlearn.student.R;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;


public class AboutActivity extends BaseFragmentActivity {

  
    private WebView webView;

    @Override
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about);
    }


   
	@Override
	protected void onInit() {
		 webView=(WebView) findViewById(R.id.webview);
		// 支持javascript
		 webView.getSettings().setJavaScriptEnabled(true);

		 webView.getSettings().setUseWideViewPort(true);
			// 自适应屏幕
		 webView.getSettings().setLayoutAlgorithm(
					LayoutAlgorithm.SINGLE_COLUMN);
		 webView.getSettings().setLoadWithOverviewMode(true);

		 webView.setWebViewClient(new WebViewClient(){

			@Override
			public void onPageFinished(WebView view, String url) {
				// TODO Auto-generated method stub
				super.onPageFinished(view, url);
				hideLoading();
			}
			 
		 });

	}

	@Override
	protected void onData() {
		
		getAboutData();
		
	}

	private void getAboutData() {
		showLoading();
		HashMap<String, Object> sentMap=new HashMap<String, Object>();
		sentMap.put("type", "about");
		String requestUrl=ParamsUtils.buildParams(NetWorkApi.ABOUT_API, sentMap);
		MyAsyncHttp.get(mContext, requestUrl, new AsyncCallBackListener() {
			
			@Override
			public void onAsyncCallBack(RESULTCODE resuleCode, String request,
					String result) {
				if (resuleCode == RESULTCODE.SUCCESS) {
					JSONObject obj;
					try {
						obj = new JSONObject(result);
						if (obj != null) {
							String url = obj.getString("data");
							webView.loadUrl(url);
						}

					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}

				}
				
			}
		});
		
	}
	
	public void onBack(View view){
		finish();
	}
}
